import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import CarSelection from "@/pages/CarSelection";
import ArticleDetail from "@/pages/ArticleDetail";
import CarDetail from "@/pages/CarDetail";
import ArticleEdit from "@/pages/ArticleEdit";
import UserManageArticle from "@/pages/UserManageArticle";

let originPushMethod = VueRouter.prototype.push;

//重写push方法
VueRouter.prototype.push = function(location, resolve, reject) {
    if (resolve && reject) {
        originPushMethod.call(this, location, resolve, reject);
    } else {
        originPushMethod.call(this, location, () => {}, () => {});
    }
}

export default new VueRouter({
    routes: [
        {
            path: '/home',
            component: Home,
            meta: {
                show: true
            }
        },
        {
            path: '/search/:keyword',
            component: Search,
            name: 'search',
            meta: {
                show: true
            }
        },
        {
            path: '/login',
            component: Login,
            name: 'Login',
            meta: {
                show: true
            }
        },
        {
            path: '/register',
            component: Register,
            meta: {
                show: true
            }
        },
        {
            path: '/carSelection',
            component: CarSelection,
            meta: {
                show: false
            }
        },
        {
            path: '/arti/edit',
            component: ArticleEdit,
            name: "ArticleEdit",
            meta: {
                show: true
            }
        },
        {
            path: '/article/detail/:id',
            component: ArticleDetail,
            name: "ArticleDetail",
            meta: {
                show: true
            }
        },
        {
            path: '/car/detail/:id',
            component: CarDetail,
            name: "CarDetail",
            meta: {
                show: true
            }
        },
        {
            path: '/article/my',
            component: UserManageArticle,
            name: "UserManageArticle",
            meta: {
                show: true
            }
        },
        {
            path: '/',
            redirect: '/home'
        }
    ]
})
